package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author：cxl
 * @Package：com.itheima.service
 * @Project：web-project
 * @name：DeptServiceImpl
 * @Date：2025-09-25 9:42 am
 * @Filename：DeptServiceImpl
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();

    }

    @Override
    public int deleteById(Integer id) {
        int row = deptMapper.deleteById(id);
        return row;
    }

    @Override
    public void add(Dept dept) {
        dept.setCreateTime(LocalDateTime.now());
        //防止重复创建对象
        dept.setUpdateTime(dept.getCreateTime());
        deptMapper.insert(dept);
    }

    @Override
    public Dept update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
        return dept;
    }

    @Override
    public Dept getById(Integer id) {
        return deptMapper.selectById(id);
    }
}
